package com.xmx.ndmallwxapi.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.xmx.common.holder.LoginUserHolder;
import com.xmx.common.utils.R;
import com.xmx.ndmallwxapi.feign.UserFeignClient;
import com.xmx.ndmallwxapi.service.CartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx/feedback")
public class FeedbackController {
    @Resource
    CartService cartService;

    @Resource
    UserFeignClient userFeignClient;

    @Resource
    LoginUserHolder userHolder;

    @PostMapping("/submit")
    public R goodscount(@RequestBody Map<String, Object>  feedback){
        System.out.println(feedback);
        String picUrls = JSONUtils.toJSONString(feedback.get("picUrls"));
        Integer userId = userHolder.getCurrentUser().getId();
        feedback.replace("picUrls",picUrls);
        feedback.put("userId",userId);
        feedback.put("username","user123");
        feedback.put("status",1);
        userFeignClient.save(feedback);
        return R.ok().put("data",feedback);
    }
}
